package com.example.administrator.appli;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.example.administrator.appli.Iinteface.IMulity;
import com.example.administrator.appli.service.LocalServiceCount;
import com.example.administrator.appli.service.LocalServiceMulity;

public class LocalServiceActivity2 extends Activity {
    private static final String TAG = "LocalServiceActivity2";
    //
    IMulity iMulity;
    public LocalServiceMulity.ServiceBinder serviceBinder;
    ServiceConnection connection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            iMulity = (IMulity) service;
            serviceBinder = (LocalServiceMulity.ServiceBinder) service;
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {

        }
    };
    TextView tv_add;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_local_service);

        initView();
        Intent intent = new Intent(this, LocalServiceMulity.class);
        bindService(intent, connection, Context.BIND_AUTO_CREATE);
        tv_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //通过接口、Binder均可计算
                tv_add.setText(iMulity.mulity(10, 10) + "\n" + serviceBinder.mulity(10, 10) + "");
            }
        });

    }

    private void initView() {
        tv_add = (TextView) findViewById(R.id.tv_add);
    }

}
